home *** CD-ROM | disk | FTP | other *** search
- ;---------------------------- SetupFontMap -------------------------------
-
- ; Written by Ray.A.Cameron
- ; Version 1.0
- ; Mon May 4, 1987 21:41:50
-
-
- XDef SetupFontMap ; Routine's name
- XDef FontMap ; Global location for the FontMap's Handle
-
-
- ;---------- Includes -------------
-
- Include Traps.D ; Use System and ToolBox traps
- Include PackMacs.Txt ; Use Package Equates
-
-
- ; ---------- Equates ----------
-
- True Equ 1
- False Equ 0
- FNum Equ %1111111111000000
- FSize Equ %0000000000111111
-
-
- SetupFontMap
-
- Link A6,#0
- Movem.l D0-D7/A0-A4,-(SP) ; Save the existing register values.
-
- ; Function CountResources (theType: ResType): Integer;
- Clr.w -(SP) ; Clear for answer.
- Move.l #'FONT',-(SP) ; Count the number of 'FONT' resources.
- _CountResources
- Clr.l D7
- Move.w (SP)+,D7 ; Store the result.
-
- ; Create a non-relocatable block into which will be stored each font
- ; resource ID, if the resource has a font size (ie no name).
- Move.l D7,D0 ; Create a size to allow 2 bytes for
- Lsl.w #1,D0 ; each resource ID.
- _NewPtr ,Clear
- Movea.l A0,A4 ; Store pointer to non-relocatable block.
-
- ; Setup the Resource Manager so that the resources aren't loaded into
- ; memory.
- ; Procedure SetResLoad (load: Boolean);
- Move.b #False,-(SP) ; Load False
- _SetResLoad
-
- Clr.w D3 ; Loop counter (# of font resources).
- Clr.w D4 ; Offset into the theID non-relocatable block.
- Clr.w D5 ; The number of different fonts.
- Clr.l D6 ; The # of bytes to allocate to FontMap.
- ; Setup a non-relocatable block for the name of a resource.
- Move.l #256,D0 ; The # of bytes required.
- _NewPtr ,Clear
- Move.l A0,thename(A5) ; Store pointer.
-
- ExamRes
- Addq.w #1,D3 ; increment loop counter.
- ; Obtain a handle to a resource with type 'FONT' and an index value from
- ; 1-to-CountResources.
- ; Function GetIndResource (theType: resType; index: Integer): Handle;
- Clr.l -(SP) ; Space for handle
- Move.l #'FONT',-(SP) ; Font resource type
- Move.w D3,-(SP) ; Index value
- _GetIndResource
-
- ; Use the handle to obtain the resources ID and name.
- ; Procedure GetResInfo (theResource: Handle; VAR theID: Integer;
- ; Var theType: ResType; Var name: Str255);
- ; The handle is already on the stack.
- Pea theID(A5) ; point to theID
- Pea theType(A5) ; point to theType
- Move.l thename(A5),-(SP) ; load the address of the name
- _GetResInfo
-
- Move.w theID(A5),D0 ; Examine theID to see if the resource
- Andi.w #FSize,D0 ; has a font size (ie no name).
- Beq.s NoSize ; NoSize, ie a name-> NoSize
- ; Place theID of the font resource (which contains a font size) into
- ; the non-relocatable block. Then increment the offset.
- Move.w theID(A5),(A4,D4.W)
- Addq.w #2,D4 ; increment the offset
- Bra.s Testloop
-
- NoSize
- Movea.l thename(A5),A0
- ; Evaluate the number of bytes to allocate to this font's name in the
- ; FontMap. Add this to the running total.
- Clr.l D0
- Move.b (A0),D0 ; Create an even length for the name
- Bset.l #0,D0 ; (ie add padding if its rEquired).
- Addq.l #1,D0
- Add.l D0,D6 ; Update the running total.
- Move.l A0,-(SP) ;Place the pointer to the name and
- Move.w theID(A5),-(SP) ; the resource ID onto the stack.
- Addq.w #1,D5 ; Increment the number of different fonts.
- ; Create a new non-relocatable block for the next font resource name.
- Move.l #256,D0 ; The # of bytes required.
- _NewPtr ,Clear
- Move.l A0,thename(A5) ; Store pointer
-
- Testloop
- Cmp.w D3,D7 ; Have all font resources been
- Bne.s ExamRes ; examined, No -> ExamRes
-
- ; Dispose of the pointer in thename(A5) because it is not required.
- Movea.l thename(A5),A0
- _DisposPtr
-
- ; Setup the Resource Manager so that the resources can be loaded into
- ; memory.
- ; Procedure SetResLoad (load: Boolean);
- Move.b #True,-(SP) ; Load True
- _SetResLoad
-
- ; Evaluate the number of bytes required for the FontMap. Then create
- ; a relocatable block for the FontMap. D6 contains the number of bytes
- ; to allocate for the font names in the FontMap.
- Addq.l #2,D6 ; 2 bytes for "the number of fonts"
- Clr.l D0
- Move.w D5,D0 ; The # of different fonts, each font
- Mulu #6,D0 ; list rEquires 6 bytes.
- Add.l D0,D6
- Move.l D0,D3 ; Reserved for later.
-
- ; The amount of space to allocate for the font sizes is 2 x the number
- ; of font resources. This allows one word per entry.
- Lsl.l #1,D7
- Add.l D7,D6 ; Grand Total in D6
-
- Move.l D6,D0
- _NewHandle
- Move.l A0,FontMap(A5) ; Store the FontMap handle.
- Movea.l A0,A2 ; Copy the handle.
- ; Lock the FontMap while the font information is placed into it.
- _HLock
-
- Movea.l (A2),A2 ; Obtain the address of the FontMap.
- Subq.w #1,D5 ; The number of fonts- 1.
- Move.w D5,(A2) ; Store the # of fonts- 1 in the FontMap.
-
- Lea.l 2(A2,D3.W),A1 ; Point to the start of the font name list.
- Lea.l 2(A2),A0 ; Point to the start of the font info list.
-
- ; Transfer theID and the name pointer onto the FontMap from the stack.
- Transfer
- Move.w (SP)+,(A0)+ ; theID
- Move.l (SP)+,(A0)+ ; name pointer.
- Cmpa.l A0,A1 ; Have all the resources been transfered?
- Bne.s Transfer ; No -> Transfer.
-
- ; The information on the FontMap, in the font info list is now sorted
- ; so that the first font info has the lowest (alphabetically) name
- ; associated with it.
- Move.w (A2),D7
- Mulu #6,D7 ; Point to the last entry in the list
- @1 Move.w D7,D6
- @2 Subq.w #6,D6
- Bmi.s @3
- Movea.l 2+2(A2,D7.W),A1 ; Load pointer to aStr
- Movea.l 2+2(A2,D6.W),A0 ; Load pointer to bStr
- ; Compare the two strings.
- ; Function IUMagString (aPtr, bPtr: Ptr; aLen, bLen: Integer): Integer;
- Clr.w -(SP) ; Clear for result.
- Pea 1(A1) ; Address of aStr
- Pea 1(A0) ; Address of bStr
- Clr.w D0
- Move.b (A1),D0
- Move.w D0,-(SP) ; Length of aStr
- Move.b (A0),D0
- Move.w D0,-(SP) ; Length of bStr
- _IUMagString ; Compare aStr and bStr
- Move.w (SP)+,D0
- Cmpi.w #1,D0 ; Was aStr greater than bstr
- Beq.s @2 ; Yes -> @2.
-
- ; Swap the theID and the name pointers over
- Move.w 2(A2,D7.W),D0 ; Swap theIDs over
- Move.w 2(A2,D6.W),2(A2,D7.W)
- Move.w D0,2(A2,D6.W)
- Move.l 2+2(A2,D7.W),D0 ; Swap the pointers over
- Move.l 2+2(A2,D6.W),2+2(A2,D7.W)
- Move.l D0,2+2(A2,D6.W)
- Bra.s @2
-
- @3 Subq.w #6,D7 ; Shorten the search and repeat until
- Bne.s @1 ; the table is completely sorted.
-
- ; Now that the entries in the font info list have been sorted the font
- ; names are loaded into the FontMap and the name pointer is now
- ; replaced by a two byte offset, As each font name is loaded its
- ; non-relocatable block is disposed of.
- Move.w (A2),D5
- Addq.w #1,D5 ; The number of fonts.
- Mulu #6,D5
- Addq.w #2,D5
- ; D5 contains the offset to the postion of the first font name.
-
- Clr.w D7 ; loop counter (the # of fonts - 1)
- LoadNames
- Move.w D7,D6
- Mulu #6,D6 ; Point to the next font info
- Movea.l 2+2(A2,D6.W),A3 ; Obtain the pointer to the name.
- Move.w D5,2+2(A2,D6.W) ; Store name offset in FontMap.
-
- ; Perform a BlockMove to load the font's name.
- ; Procedure BlockMove (sourcePtr, destPtr: Ptr; byteCount: Size);
- Clr.l D0
- Move.b (A3),D0
- Bset.l #0,D0
- Addq.l #1,D0 ; # of bytes required to move.
- Lea (A3),A0 ; load source address
- Lea (A2,D5.W),A1 ; load destination address
- Add.w D0,D5 ; point to next name (offset)
- _BlockMove
- Movea.l A3,A0 ; Dispose of the non-relocatable block
- _DisposPtr ; it's no longer required.
-
- Addq.w #1,D7 ; increment counter
- Cmp.w (A2),D7
- Ble.s LoadNames
-
- ; Load the font sizes
- Clr.w D7 ; loop counter
- LdFSizes
- Lea (A2,D5.W),A0
- Clr.w (A0)
- Move.w D7,D6
- Mulu #6,D6 ; Point to the next font info
- Move.w 2(A2,D6.W),D3 ; theID of the font
- Move.w D5,4+2(A2,D6.W) ; Store size list offset in FontMap
- Clr.w D2 ; Offset into the theID block
- @1 Move.w (A4,D2.W),D0 ; Obtain the next theID
- Andi.w #FNum,D0
- Cmp.w D3,D0
- Bne.s @2
- Move.w (A4,D2.W),D0
- Andi.w #FSize,D0
- Addq.w #1,(A0) ; Increment "# of font sizes" counter
- Move.w (A0),D1 ; Offset to place font size in list
- Lsl.w #1,D1 ; Doubled to allow for word length.
- Move.w D0,(A0,D1.W) ; Store the font size
- @2 Addq.w #2,D2 ; Increment offset counter
- Cmp.w D2,D4 ; Examined the complete block
- Bgt.s @1 ; No -> @1.
-
- ; Sort the font size list in order of smallest to largest.
- Move.w (A0),D3 ; The # of font sizes
- Lsl.w #1,D3 ; Offset to the last font size
- Sort1
- Move.w D3,D2
- Sort2
- Subq.w #2,D2
- Beq.s Sort3
- Move.w (A0,D3.W),D1
- Cmp.w (A0,D2.W),D1
- Bgt.s Sort2
- Move.w (A0,D2.W),(A0,D3.W)
- Move.w D1,(A0,D2.W)
- Bra.s Sort2
- Sort3
- Subq.w #2,D3
- Bne.s Sort1
-
- ; Convert the font "theID" into the font number
- Move.w 2(A2,D6.W),D3
- Lsr.w #7,D3
- Move.w D3,2(A2,D6.W)
-
- ; Update the offset in the FontMap (D5) to point to the location of the
- ; font sizes associated with the next font.
- Move.w (A0),D0
- Addq.w #1,D0
- Lsl.w #1,D0
- Add.w D0,D5
-
- ; Check to see if there are any more fonts to load into the FontMap.
- Addq.w #1,D7
- Cmp.w (A2),D7
- Ble.s LdFSizes
-
- ; The FontMap has been created, and loaded with its information.
- ; Dispose of the theID non-relocatable block and unlock the FontMap.
- Movea.l A4,A0
- _DisposPtr
- Movea.l FontMap(A5),A0
- _HUnlock
-
- ; Restore registers to their original values
- Movem.l (SP)+,D0-D7/A0-A4
- Unlk A6
-
- Rts
-
-
- ; ---------- Variables ----------
-
- theID Ds.w 1
- theType Ds.l 1
- thename Ds.l 1
- FontMap Ds.l 1 ; Handle of the FontMap.
-
- End